#include "header.h"
extern monster monDB[100];
monster::monster()
{
}

monster::monster(string nname,int nhp,int npower,int ndefense, gemElement nelement, double nforceres, double nmagicres, double npsychres)
{
  name = nname;
  hp = nhp;
  maxhp = nhp;
  power = npower;
  defense = defense;
  element = nelement;
  forceResist = nforceres;
  magicResist = nmagicres;
  psychResist = npsychres;
}

void monster::setMonster(string nname,int nhp,int npower,int ndefense, gemElement nelement, double nforceres, double nmagicres, double npsychres)
{
  name = nname;
  hp = nhp;
  maxhp = nhp;
  power = npower;
  defense = defense;
  element = nelement;
  forceResist = nforceres;
  magicResist = nmagicres;
  psychResist = npsychres;
}

double monster::resistFactor(gemElement nelement, gemType ntype)
{
  double total=1;
  switch (element) //element of the monster, nelement is the attack element
  {
    case light:
      if (nelement==light) total*=.5;
      if (nelement==dark) total*=1.5;
      break;
    case fire:
      if (nelement==fire) total*=0;
      if (nelement==elec) total*=.5;
      if (nelement==water) total*=2;
      if (nelement==ice) total*=1.5;
      break;
    case water:
      if (nelement==water) total*=0;
      if (nelement==earth) total*=.5;
      if (nelement==air) total*=2;
      if (nelement==elec) total*=1.5;
      break;
    case air:
      if (nelement==air) total*=0;
      if (nelement==ice) total*=.5;
      if (nelement==fire) total*=2;
      if (nelement==earth) total*=1.5;
      break;
    case elec:
      if (nelement==elec) total*=0;
      if (nelement==fire) total*=.5;
      if (nelement==earth) total*=2;
      break;
    case earth:
      if (nelement==earth) total*=0;
      if (nelement==water) total*=.5;
      if (nelement==ice) total*=2;
      break;
    case ice:
      if (nelement==ice) total*=0;
      if (nelement==air) total*=.5;
      if (nelement==elec) total*2;
      break;
    case dark:
      if (nelement==dark) total*=.5;
      if (nelement==light) total*=1.5;
    
  } // end element switch
  
  switch (ntype) //type of the attack
  {
    case force:
      total*=forceResist;break;
    case magic:
      total*=magicResist;break;
    case psych:
      total*=psychResist;break;
  }
  
  return total;
}

void monsterCopy(monster source, monster &dest)
{
  dest.name = source.name;
  dest.hp = source.hp;
  dest.maxhp = source.maxhp;
  dest.power = source.power;
  dest.defense = source.defense;
  dest.element = source.element;
  dest.forceResist = source.forceResist;
  dest.magicResist = source.magicResist;
  dest.psychResist = source.psychResist;
}

void monsterDBInit()
{
  monDB[0].setMonster("Goblin",200,100,150,dark,1,1,1.5);
  monDB[1].setMonster("Goblin",200,100,150,earth,1,1,1.5);
  monDB[2].setMonster("Tortoise",450,100,300,water,1,2,1);
}
